/**
 * 
 */
package net.sf.cldsql.sql2json.demo;

import net.sf.cldsql.dj.db.QueryResult;
import net.sf.cldsql.dj.mvc.DiServiceImpl;
import net.sf.cldsql.dj.mvc.DiContext;
import net.sf.cldsql.dj.utl.CollUtl;

/**
 * SjDemoServiceImpl
 * 
 * Demo of Sj Service
 */
public class SjDemoServiceImpl extends DiServiceImpl implements SjDemoService {
    
    private SjDemoQuery query;

    public void init() {
        this.query = container.get(SjDemoQuery.class);
    }
    
    public QueryResult execEcho (final DiContext ctx, final String... args) {
        return query.execEcho(CollUtl.toMap(
                "message", ctx.getParam("message")));
    }

    public QueryResult execGet (final DiContext ctx, final String... args) {
        return query.execGet(CollUtl.toMap(
                "id", args[0]));
    }

    public QueryResult execGetAll(final DiContext ctx, final String... args) {
        return query.execGetAll(null);
    }

    public QueryResult execPost(final DiContext ctx, final String... args) {
        return query.execPost(CollUtl.toMap(
                "id", args[0],
                "name", ctx.getParam("name")));
    }

    public QueryResult execPut(final DiContext ctx, final String... args) {
        return query.execPut(CollUtl.toMap(
                "name", ctx.getParam("name")));
    }

    public QueryResult execDelete(final DiContext ctx, final String... args) {
        return query.execDelete(CollUtl.toMap(
                "id", args[0]));
    }

}
